package com.yuexunit.finance.project.action.v1;

import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.project.action.v1.model.AuditWarning;
import com.yuexunit.finance.project.entity.AuditWarningEntity;
import com.yuexunit.finance.project.service.AuditWarningService;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;


/**
 * @author wenwenlong
 */
@Implements(WarningCenterActionApi.class)
public class WarningCenterActionApiImpl implements WarningCenterActionApi {
	private AuditWarningService auditWarningService = ComponentFactory.loadClass(AuditWarningService.class);

	@Override
	public void updateAuditWarning(String auditWarningId, String auditStation, Long auditStationId, Integer agingTime, Integer warningTime) {
		AuditWarningEntity entity = auditWarningService.inquireAuditWarning(auditWarningId);
		entity.setAuditStation(auditStation);
		entity.setAuditStationId(auditStationId);
		entity.setWarningTime(warningTime);
		entity.setAgingTime(agingTime);
		auditWarningService.updateAuditWarning(entity);
	}
	
	@Override
	public AuditWarning inquireAuditWarning(String auditWarningId) {
		AuditWarningEntity entity = auditWarningService.inquireAuditWarning(auditWarningId);
		AuditWarning aw = new AuditWarning();
		BeanUtils.copyProperties(entity, aw);
		return aw;
	}

	@Override
	public PageList<AuditWarning> inquireAuditWarningPageList(PageCriteria page) {
		PageList<AuditWarningEntity> pages = auditWarningService.inquireAuditWarningPageList(page);
		PageList<AuditWarning> results = new PageList<>(page, pages.getTotalRecordCount());
		for (AuditWarningEntity awe : pages) {
			AuditWarning aw = new AuditWarning();
			BeanUtils.copyProperties(awe, aw);
			results.add(aw);
		}
		return results;
	}
}
